<template>
  <div>
    <el-dialog title="角色管理" :visible="showDialog" @close="closeFn">
      <el-checkbox-group v-model="checkList">
        <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id ">{{ item.name }}</el-checkbox>
      </el-checkbox-group>
      <el-row type="flex" justify="center">
        <el-button type="primary" @click="confirmFn">确认</el-button>
        <el-button @click="closeFn">取消</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { getRoleList } from '@/api/setting'
import { getUserDetails, updateAssignRole } from '@/api/user'
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      checkList: [],
      roleList: [],
      id: ''
    }
  },
  async created() {
    const { rows } = await getRoleList()
    this.roleList = rows
  },
  methods: {
    async getRoleDetailsFn(id) {
      const { roleIds } = await getUserDetails(id)
      this.checkList = roleIds
      this.id = id
    },
    async confirmFn() {
      await updateAssignRole({ id: this.id, roleIds: this.checkList })
      this.$message.success('修改成功')
      this.$emit('update:showDialog', false)
    },
    closeFn() {
      this.$emit('update:showDialog', false)
    }
  }
}
</script>

<style>

</style>
